#pragma once
#include "Scene.h"
#include "Line.h"
#include "Sphere.h"
#include "Material.h"
#include "vector3f.h"
#include "Vector2.h"
#include "Triangle.h"

class GeometricTools
{
public:
	static const float FloatSmallValue;
public:
	GeometricTools(void);
	~GeometricTools(void);
	static bool Intersect(Scene *pScene, Line* pLine);
	static bool Intersect(
        Scene *scene, Line& line, Triangle* triangle, Vector3f* intersectionPoint, 
        Vector3f* surfaceNormal, Material* material);

	static Vector2 CalculateTextureCoordinate(Triangle& triangle, Vector3f& intersectionPoint);

	static void Refract(Line& incidentRay,
        Triangle& triangle, Vector3f& intersectionPoint, Vector3f& surfaceNormal,
		Material& currentMaterial, Material& material, Line* refraction);

	static void Reflect(Line& incidentRay,
        Triangle& triangle, Vector3f& intersectionPoint, Vector3f& surfaceNormal, 
        Line* reflectionRay);


public:   
    // line intersect with XY plane(Z==0)
    // @return: return true if intersect in the positive direction of the line.
    // @fLineNormal: if intersect, set the fPointIntersect.
    static bool LineIntersectXYPlane(
        float* fLineDirection, float* fLinePoint, 
        float* fPointIntersect);


    // line intersect with arbitrary plane
    // @return: return true if intersect in the positive direction of the line.
    // @fLineNormal: if intersect, set the fPointIntersect.
    static bool LineIntersectPlane(
        float* fLineDirection, float* fLinePoint, 
        float* fPlaneNormal, float* fPlanePoint,
        float* fPointIntersect);



    // line intersect with a sphere
    // @return: return true if intersect the sphere.
    // @fLineNormal: if intersect, set the fPointIntersect.
    static bool LineIntersectSphere(
        float* fLineDirection, float* fLinePoint, float* fShpereCenter, float fSpereRadius,
        float* fPointIntersect);

    static bool LineIntersectSphere(
        Sphere *pSphere, Line* line, Vector3f* intersectionPoint, Vector3f* surfaceNormal, 
        Material* material, Line* reflectionRay);


};

